/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lucava.importer.uspeed;

import java.io.FileNotFoundException;
import java.io.IOException;
import lucava.importer.java.XmlImporter;
import lucava.metamodel.dot.DotGraph;
import lucava.metamodel.dot.visitor.DotFileGenerator;
import lucava.metamodel.java.MetaModel;
import lucava.metamodel.java.visitor.DotMetaModelGenerator;
import lucava.metamodel.java.visitor.JavaFileGenerator;
import lucava.metamodel.uspeed.UspeedDocument;
import lucava.metamodel.uspeed.visitor.XmlVisitor;
import lucava.util.FileBuffer;
import lucava.util.FileBufferWriter;
import lucava.util.GraphVizGenerator;
import org.jdom2.JDOMException;

/**
 *
 * @author glenn
 */
public class Uspeed {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException,
            IOException, JDOMException {

        FileImporter parser = new FileImporter();
        UspeedDocument document = parser.load("data/uspeedModel.uspeed",true);

        XmlVisitor visitor = new XmlVisitor();
        document.accept(visitor);

        visitor.export("data/test.xml");

        XmlImporter importer = new XmlImporter();
        MetaModel model = importer.load("data/test.xml");

        DotMetaModelGenerator dotGen = new DotMetaModelGenerator();
        model.accept(dotGen);

        DotGraph graph = dotGen.getGeneratedGraph();

        DotFileGenerator generator = new DotFileGenerator();
        graph.accept(generator);
        FileBuffer generatedDot = generator.getGeneratedFile();
        FileBufferWriter.generateFileFor(generatedDot);

        GraphVizGenerator.generatePNGFromFile(graph.getName() + ".dot", "data/uspeedModel.png");

        JavaFileGenerator codegen = new JavaFileGenerator();
        model.accept(codegen);

    }
}
